import { IBizLabTemplate } from "@ibizlab/template";

/**
 * 加 运算助手 {{add 12 412}} {{add '124' '512'}}
 *
 * @export
 * @class Add
 */
export class Add {
  /**
   * Creates an instance of Add.
   * @param {IBizLabTemplate} template
   * @memberof Add
   */
  constructor(template: IBizLabTemplate) {
    template.engine.registerHelper("add", (...args: unknown[]) => {
      const items = args.slice(0, args.length - 1);
      let isString: boolean = items.some((item: any) => {
        return isNaN(Number(item));
      });
      let result: any = isString ? '' : 0;
      items.forEach((item: any) => {
        result += isString ? item : Number(item);
      });
      return result;
    });
  }
}
